
  # needs to be run with jruby
  require 'java'
  require 'digest/md5'
  require 'net/http'
  require 'logger'
 
  # ensure you have all the batik jar files in your CLASSPATH
  import 'java.io.IOException';
  import 'org.apache.batik.dom.svg.SVGDOMImplementation'
  import 'org.apache.batik.dom.svg.SAXSVGDocumentFactory'
  import 'org.apache.batik.util.XMLResourceDescriptor'
  import 'org.apache.batik.transcoder.image.PNGTranscoder'
  import 'org.apache.batik.transcoder.image.JPEGTranscoder'
  import 'org.apache.batik.transcoder.TranscoderOutput'
  import 'org.apache.batik.transcoder.TranscoderInput'
  import 'java.awt.image.BufferedImage'
  import 'java.io.FileOutputStream'
  import 'java.io.ByteArrayOutputStream'
  import 'java.io.OutputStreamWriter'
  import 'org.w3c.dom.Document';

class VeeGee
  attr_accessor :uri, :cacheKey, :format, :log
    
  def initialize(uri)

    @log = Logger.new("/home/cache/sinatra-veegee.log")
    @log.info('HLADFADF '+uri) 		
    @uri = uri
    @tokens = [ ]
    @cacheKey = Digest::MD5.hexdigest(@uri)  
    @log.info('HLADFADF '+@uri)
  end

  def to_s
    @uri
  end

  def add_token( token )
    @tokens << token
  end

  # Support templating of member data.
  def get_binding
    binding
  end

  # 
  def render(whereabouts)

   @log.info whereabouts
   @log.info @uri
       
    # rasterize as PNG
    r = PNGTranscoder.new();

    # @todo - svn with need interpolating with cgi params, string svgURI = new File(inputFilename).toURL().toString();
    input = TranscoderInput.new(@uri) 
  
    @log.info(input)
    ostream = FileOutputStream.new(whereabouts)
    output = TranscoderOutput.new(ostream)
    r.transcode(input, output)
    ostream.flush();
    ostream.close();

  end
  
end
